package com.huaxia.controller.excellent;

import com.huaxia.pojo.excellent.*;
import com.huaxia.service.excellent.ExcellentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/06/09 17:16
 */
@RestController
@RequestMapping("/excellent")
public class ExcellentController {
    @Autowired
    private WebApplicationContext webApplicationContext;
    @Autowired
    private ExcellentService excellentService;

    @GetMapping("/getBranchMDRT")
    public List<BranchMDRT> getBranchMDRT(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchMDRT> branchMDRTs = (List<BranchMDRT>) servletContext.getAttribute("branchMDRTs");
        if(branchMDRTs==null){
            branchMDRTs = excellentService.getBranchMDRT();
            servletContext.setAttribute("branchMDRTs",branchMDRTs);
            return branchMDRTs;
        }
        return branchMDRTs;
    }

    @GetMapping("/getSaleDeptMDRT")
    public List<SaleDeptMDRT> getSaleDeptMDRT(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptMDRT> saleDeptMDRTs = (List<SaleDeptMDRT>) servletContext.getAttribute("saleDeptMDRTs");
        if(saleDeptMDRTs==null){
            saleDeptMDRTs = excellentService.getSaleDeptMDRT();
            servletContext.setAttribute("saleDeptMDRTs",saleDeptMDRTs);
            return saleDeptMDRTs;
        }
        return saleDeptMDRTs;
    }

    @GetMapping("/getBranchFHS")
    public List<BranchFHS> getBranchFHS(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchFHS> branchFHSs = (List<BranchFHS>) servletContext.getAttribute("branchFHSs");
        if(branchFHSs==null){
            branchFHSs = excellentService.getBranchFHS();
            servletContext.setAttribute("branchFHSs",branchFHSs);
            return branchFHSs;
        }
        return branchFHSs;
    }

    @GetMapping("/getSaleDeptFHS")
    public List<SaleDeptFHS> getSaleDeptFHS(){
        return excellentService.getSaleDeptFHS();
    }

    @GetMapping("/getSzFHS")
    public List<SzFHS> getSzFHS(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SzFHS> szFHSs = (List<SzFHS>) servletContext.getAttribute("szFHSs");
        if(szFHSs==null){
            szFHSs = excellentService.getSzFHS();
            servletContext.setAttribute("szFHSs",szFHSs);
            return szFHSs;
        }
        return excellentService.getSzFHS();
    }

    @GetMapping("/getBranchQuarterFHS")
    public List<BranchQuarterFHS> getBranchQuarterFHS(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchQuarterFHS> branchQuarterFHSs = (List<BranchQuarterFHS>) servletContext.getAttribute("branchQuarterFHSs");
        if(branchQuarterFHSs==null){
            branchQuarterFHSs = excellentService.getBranchQuarterFHS();
            servletContext.setAttribute("branchQuarterFHSs",branchQuarterFHSs);
            return branchQuarterFHSs;
        }
        return branchQuarterFHSs;
    }

    @GetMapping("/getSaleDeptQuarterFHS")
    public List<SaleDeptQuarterFHS> getSaleDeptQuarterFHS(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptQuarterFHS> saleDeptQuarterFHSs = (List<SaleDeptQuarterFHS>) servletContext.getAttribute("saleDeptQuarterFHSs");
        if(saleDeptQuarterFHSs==null){
            saleDeptQuarterFHSs = excellentService.getSaleDeptQuarterFHS();
            servletContext.setAttribute("saleDeptQuarterFHSs",saleDeptQuarterFHSs);
            return saleDeptQuarterFHSs;
        }
        return saleDeptQuarterFHSs;
    }

}
